package controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.google.gson.Gson;

import model.MiniCart;

/**
 * Servlet implementation class AddToCart
 */
@WebServlet("/AddToCart")
public class AddToCart extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final int DAY_SECONDS = 86400;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String inventoryId = request.getParameter("inventoryId");
		String count = request.getParameter("count");
		HttpSession session = request.getSession();
		session.setMaxInactiveInterval(DAY_SECONDS);
		MiniCart miniCart = MiniCart.get(session);
		miniCart.addItem(inventoryId, count);
		session.setAttribute("miniCart", miniCart);
		Gson gson = new Gson();
		System.out.println(gson.toJson(miniCart));
	}



	


}
